﻿using AutoMapper;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
 
     
    internal class Program
    {
        private static IMapper _mapper;
        static void Main(string[] args)
        {
            

        }
 
    }

    public class StudentA
    {
        [SugarColumn(IsPrimaryKey = true)]
        public int StudentId { get; set; }
        public string Name { get; set; }
        public int SchoolId { get; set; }
        [Navigate(NavigateType.OneToOne, nameof(SchoolId))]//一对一
        public SchoolA SchoolA { get; set; }
        [Navigate(NavigateType.OneToMany, nameof(BookA.studenId))]//一对多
        public List<BookA> Books { get; set; }//只能是null不能赋默认值

    }
    public class SchoolA
    {
        [SugarColumn(IsPrimaryKey = true)]
        public int SchoolId { get; set; }
        public string SchoolName { get; set; }
        [Navigate(NavigateType.OneToMany, nameof(RoomA.SchoolId))]//一对多
        public List<RoomA> RoomList { get; set; }//只能是null不能赋默认值
    }

    public class RoomA
    {
        [SugarColumn(IsPrimaryKey = true)]
        public int RoomId { get; set; }
        public string RoomName { get; set; }
        public int SchoolId { get; set; }
    }
    public class BookA
    {
        [SugarColumn(IsPrimaryKey = true)]
        public int BookId { get; set; }

        public string Name { get; set; }
        public int studenId { get; set; }
    }

    var list2 = db.Queryable<StudentA>()
                 //查2层
                 .Includes(st => st.SchoolA, sch => sch.RoomList)//查询2级(等于EF ThenInclude)
                                                                 //查1层
                 .Includes(st => st.Books)
                 .ToList()
}
